function [event_clock,alg]=repair(event_clock,alg)


global NUMBER_OF_EVENTS LENGTH BIG TNOW MAINT_COST REPAIR_COST SALES_REVENUE EXP_RATE 
global SHAPE1 SCALE1 SHAPE2 SCALE2 A3 B3 B U L STATES_MAX 

% A repair has just been scheduled

event_clock(3)=BIG; % first wipe out the time of the current event

alg.revenue=alg.revenue-REPAIR_COST;
alg.old_action=1;

alg.prodcount=0;
alg.old_prodcount=alg.prodcount;
alg.time_for_failure=gamrnd(SHAPE1,SCALE1);
event_clock(2)=TNOW+0.1; % schedule a new production
alg.TR=alg.TR-REPAIR_COST;

